package eerbaar.v2.pattern.client.internal.teach;

import eerbaar.message.lib.WaitToTeachingMsg;
import eerbaar.shared.message.IMessageReader;
import eerbaar.shared.message.Message;
import eerbaar.shared.message.MsgHelper;
import eerbaar.v2.app.message.NewGameMsg;

public class TeachingMessageReader {

    private final TeachingMediator controller;

    public TeachingMessageReader(TeachingMediator controller) {
        this.controller = controller;
    }

    public void registerReaders() {

        registerWaitToTeachingReader();
    }

    private void registerWaitToTeachingReader() {

        {
            IMessageReader reader = new IMessageReader() {

                @Override
                public boolean read(Message msg) {

                    TeachingMessageReader.this.controller
                            .setState(TeachingState.WAITING_TO_TEACH);
                    return false;
                }
            };

            MsgHelper.registerReader(WaitToTeachingMsg.class, reader);
        }
        {
            IMessageReader reader = new IMessageReader() {

                @Override
                public boolean read(Message msg) {

                    TeachingMessageReader.this.controller
                            .setState(TeachingState.WAITING_TO_TEACH);
                    return false;
                }
            };

            MsgHelper.registerReader(NewGameMsg.class, reader);
        }
    }
}
